from django.shortcuts import render
from django.http import JsonResponse


def chart_list(request):
    """数据统计页面"""
    return render(request, 'chart_list.html')


def chart_bar(request):
    """ 构造柱状图 """
    legend = ['张三', '李四']
    series_list = [
        {
            'name': '张三',
            'type': 'bar',
            'data': [20, 36, 10, 10, ]
        },
        {
            'name': '李四',
            'type': 'bar',
            'data': [52, 23, 15, 33, ]
        },
    ]
    x_axis = ['第一季度', '第二季度', '第三季度', '第四季度', ]

    result = {
        'status': True,
        "data": {
            'legend': legend,
            'series_list': series_list,
            'x_axis': x_axis
        }
    }
    return JsonResponse(result)


def chart_pie(request):
    """构造饼图"""

    series_list = [
        {'value': 116546411, 'name': '工装类'},
        {'value': 165141564, 'name': '棒球服'},
        {'value': 565268580, 'name': '长裤'},
        {'value': 486115644, 'name': '短裤'},
        {'value': 300154745, 'name': '短袖'}
    ]
    result = {
        'status': True,
        "data": series_list
    }
    return JsonResponse(result)


def chart_line(request):
    """构造折现图"""

    week_list = ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']
    series_list = [150, 230, 224, 218, 135, 147, 260]
    result = {
        'status': True,
        "week_list": week_list,
        'series_list': series_list
    }
    return JsonResponse(result)
